package org.gd.hellojavacore.tests;

import java.util.*;


public class IterableTest {

    public static void main(String...a) {
        IT it = new IT();
        for (Object o: it) {
            System.out.println(o);
        }
    }

    private static final class IT implements Iterable {

        private char[] chars;

        private IT() {
            chars = new char[]{'1', '2', '3'};
        }

        public char[] getChars() {
            return chars;
        }

        /**
         * Returns an iterator over a set of elements of type T.
         *
         * @return an Iterator.
         */
        @Override
        public Iterator iterator() {
            return new Iterator() {
                private char[] chars;
                private int caret = 0;
                public Iterator setChars(char[] chars) {
                    this.chars = chars;
                    return this;
                }
                @Override
                public boolean hasNext() {
                    return chars.length > caret;
                }
                @Override
                public Object next() {
                    return chars[caret++];
                }
                @Override
                public void remove() {

                }
            }.setChars(getChars());
        }
    }

}
